<?php
	/**
	 * 连续登录奖励
	 */
    class LoginReward extends APIBase {
		
		public $tag = "LoginReward";
		
    	public function before() {
			return true;
		}
		
		public function logic() {
			$login_info = $this->data_redis->hmGet("hu:{$this->uid}", array('login_days', 'is_get'));
			
			$is_get = (int)$login_info['is_get'];
			if ($is_get == 0) {
				$login_info['login_days'] = (int) $login_info['login_days'];
				if ($login_info['login_days'] > 0) {
					$index = $login_info['login_days'];
					if($login_info['login_days'] >= 5){
						$index = 5;
					}			
					$index = $index - 1;
					$money = $this->data_redis->hincrBy("hu:{$this->uid}", "money", Game::$login_reward_money[$index]);
					$this->data_redis->hSet("hu:{$this->uid}", "is_get", 1);
					$this->returnData(array('money' => $money));
				}
			}else{
				$this->returnError(321, 'you have getted reward');
			}
		}
		
		public function after() {
    		$this->deinitDataRedis();
		}
    }
?>
